package sjms.construction.composite.e1;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName:
 * @Description:
 * @Author fcb
 * @Date 2020/6/1 14:17
 */
public class Composite extends Component {

    private List<Component> mComponents;

    public Composite(String name) {
        super(name);
        this.mComponents = new ArrayList<>();
    }

    public boolean addChil(Component component){
        return mComponents.add(component);
    }

    public boolean removeChil(Component component){
        return mComponents.remove(component);
    }

    public Component getChil(int index){
        return mComponents.get(index);
    }

    @Override
    public void operation() {
        System.out.println(this.name);
        for(Component component : mComponents){
            component.operation();
        }
    }
}
